package com.my.myrecorder.PlayAduio;

import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.my.myrecorder.R;

/**
 * Created by 张英杰 on 2016/10/14.
 */
public class VoiceActivity extends AppCompatActivity {
    private String path = null;
    private URecorder recorder;
    private UPlayer player;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_voice);


        path = Environment.getExternalStorageDirectory().getAbsolutePath();
        path += "/ione.pcm";

        recorder = new URecorder(path);
        player = new UPlayer(path);

        //开始录音
        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Toast.makeText(VoiceActivity.this, "start record", Toast.LENGTH_SHORT).show();

                recorder.start();
            }
        });

        //停止录音
        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(VoiceActivity.this, "stop record", Toast.LENGTH_SHORT).show();
                recorder.stop();
            }
        });

        //开始播放
        findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Toast.makeText(VoiceActivity.this, "start play", Toast.LENGTH_SHORT).show();
                player.start();
            }
        });

        //停止播放
        findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Toast.makeText(VoiceActivity.this, "stop play", Toast.LENGTH_SHORT).show();
                player.stop();
            }
        });
    }

}
